package com.example.HelloSpace.utils;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.Window;

import androidx.core.content.ContextCompat;

import com.example.HelloSpace.R;

public class MyApp extends Application {
    private static MyApp instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    public static MyApp getInstance() {
        return instance;
    }

    public static Context getAppContext() {
        return instance.getApplicationContext();
    }

    public static String getSERVER_URL() {
        return getInstance().getResources().getString(R.string.SERVER_URL);
    }

    public static String getRESOURCE_URL() {
        return getInstance().getResources().getString(R.string.RESOURCE_URL);
    }

    public static void updateStatusBarColorAndIcons(boolean isLightBackground, Activity activity) {
        Window window = activity.getWindow();
        View decorView = window.getDecorView();
        if (isLightBackground) {
            // 设置状态栏文字颜色为暗色（适用于浅色背景）
            decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            // 移除SYSTEM_UI_FLAG_LIGHT_STATUS_BAR标志，恢复默认的亮色状态栏文字
            decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
}